package com.lg.system.main.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.lg.system.main.dao.ShiroDao;
import com.lg.system.main.entity.Shiro;
import com.lg.system.main.service.ShiroService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dl
 * @since 2018-03-30
 */
@Transactional
@Service
public class ShiroServiceImpl extends ServiceImpl<ShiroDao, Shiro> implements ShiroService {

	
	public boolean save( Shiro shiro) {
		return super.insert(shiro);
	}

	@Override
	public boolean update(Shiro shiro) {
		return super.updateById(shiro);
	}
	
	
	@Override
	public boolean deleteById(Long id) {
		return super.deleteById(id);
	}

	@Override
	public boolean deleteByIds(List<Long> ids) {
		if(null==ids||ids.isEmpty()){
			return false;
		}
		return super.deleteBatchIds(ids);
	}

	@Override
	public List<Shiro> selectList(Map<String, Object> param) {
		EntityWrapper<Shiro>  wrapper = new EntityWrapper<Shiro>();
		wrapper.eq("is_work", 0);
		wrapper.orderBy("num", true);
		return selectList(wrapper);
	}

	@Override
	public boolean updateRows(List<Long> ids, Integer type) {
		List<Shiro> shiros=selectBatchIds(ids);
		List<Shiro> shirosnew=new ArrayList<>();
		if(shiros!=null){
			for(Shiro shiro:shiros){
				shiro.setIsWork(type);
				shirosnew.add(shiro);
			}
			return updateBatchById(shirosnew);
		}
		return false;
	}

}
